package com.practicesuite.controllayer;

import javax.swing.JPanel;

import com.practicesuite.systemlayer.Invoice;
import com.practicesuite.systemlayer.Patient;
import com.practicesuite.systemlayer.SystemDriver;
import com.practicesuite.systemlayer.User;

import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Panel for viewing invoice information for a specific patient visit.
 * 
 * @author James
 *
 */
public class ViewInvoicePanel extends JPanel {
    private static final long serialVersionUID = 1L;
    public MainWindow window;
    List<Invoice> result;
    Patient patient;

    /**
     * Create the panel.
     */
    public ViewInvoicePanel(MainWindow container, final Invoice invoice, final User user) {
        window = container;
        setPreferredSize(new Dimension(500, 400));
        setLayout(new BorderLayout(0, 0));
        //Patient patient = new Patient("", 1, 1, new Date(), "", "", "", 1, new MedicalInformation(1, "", "", ""), "", false);
        //Date date = new Date();
        Map<Double, String> services = new HashMap<Double, String>();
        services.put(100.00, "Injection");
        services.put(20.00, "Office Fee");
        services.put(00.40, "Water Charge");
        services.put(35.20, "Child Noise");
        Map<Double, String> discounts = new HashMap<Double, String>();
        discounts.put(10.50, "First time visit coupon");
        //Invoice result = new Invoice(patient, date, services, discounts);
        try {
            result = SystemDriver.getInvoice(user.getUserID());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "System error, contact administrator.");
            System.out.println("getInvoice");
            e.printStackTrace();
        }
        
        JLabel lblViewInvoice = new JLabel("View Invoice");
        lblViewInvoice.setHorizontalAlignment(SwingConstants.CENTER);
        lblViewInvoice.setFont(new Font("Tahoma", Font.PLAIN, 24));
        lblViewInvoice.setPreferredSize(new Dimension(500, 50));
        add(lblViewInvoice, BorderLayout.NORTH);
        
        try {
            JTextArea textArea = new JTextArea(invoice.toString());
            textArea.setFont(new Font("Monospaced", Font.PLAIN, 10));
            add(textArea, BorderLayout.CENTER);
        } catch (IndexOutOfBoundsException e) {
            JOptionPane.showMessageDialog(null, "Sorry, no invoice exist for your account.");
            System.out.println(result.toString());
            e.printStackTrace();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "System error, contact administrator.");
            System.out.println("get(0)");
            e.printStackTrace();
        }
        
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(500, 50));
        add(panel, BorderLayout.SOUTH);
        
        JButton btnReturnToHome = new JButton("Return to Home");
        btnReturnToHome.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int eUID = user.getEUID();
                if (eUID == 0) {
                    window.gotoPanel("adminHome", user);
                }
                else if (eUID == 1) {
                    window.gotoPanel("doctorHome", user);
                }
                else if (eUID == 2) {
                    window.gotoPanel("nurseHome", user);
                }
                else if (eUID == 3) {
                    window.gotoPanel("patientHome", user);
                }
            }
        });
        btnReturnToHome.setFont(new Font("Tahoma", Font.PLAIN, 14));
        panel.add(btnReturnToHome);

    }

}
